import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:portal_website/pages/common_header.dart';

class DoubleResourcePage extends StatefulWidget {
  @override
  _DoubleResourcePageState createState() => _DoubleResourcePageState();
}

class _DoubleResourcePageState extends State<DoubleResourcePage>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late Animation<double> _opacityAnimation;
  int _activeNavIndex = 2;

  @override
  void initState() {
    super.initState();
    // 页面加载动画
    _animationController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 500),
    );
    _opacityAnimation = Tween<double>(begin: 0, end: 1).animate(
      CurvedAnimation(parent: _animationController, curve: Curves.easeIn),
    );

    // 延迟执行动画
    Future.delayed(Duration(milliseconds: 100), () {
      _animationController.forward();
    });
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  // 导航菜单项
  final List<String> _navItems = ['首页', '政策法规', '双创资源', '动态咨询', '企业云图', '联系我们'];

  // 成功案例数据
  final List<ResourceCardData> _successCaseCards = [
    ResourceCardData(
      icon: '🏭',
      name: '智能制造创新案例',
      type: '成功案例',
      description: '某智能制造企业通过技术创新和模式创新，实现了生产效率提升30%，产品质量提高25%，市场份额扩大到行业前三。',
      contactInfo: ['成立时间：2016年', '员工人数：150+'],
    ),
    ResourceCardData(
      icon: '🌱',
      name: '现代农业创业案例',
      type: '成功案例',
      description: '专注于现代农业技术研发与应用，分享如何利用科技创新提升传统农业、开拓农产品高端市场的成功经验。',
      contactInfo: ['成立时间：2015年', '员工人数：200+'],
    ),
  ];

  // 第三方服务机构数据
  final List<ResourceCardData> _thirdPartyServiceCards = [
    ResourceCardData(
      icon: '💼',
      name: '创新咨询公司',
      type: '咨询服务',
      description: '提供商业模式设计、市场调研、战略规划等专业咨询服务，帮助创业者清晰定位，制定科学的发展路径。',
      contactInfo: ['电话：0371-1111111', '邮箱：consult@demo.com'],
    ),
    ResourceCardData(
      icon: '💰',
      name: '创业投资基金',
      type: '金融服务',
      description: '专注于早期项目投资，提供种子轮、天使轮融资服务，同时为创业者提供投后管理和资源对接支持。',
      contactInfo: ['电话：0371-2222222', '官网：www.vc-demo.com'],
    ),
    ResourceCardData(
      icon: '👥',
      name: '人力资源服务',
      type: '人才服务',
      description: '提供人才招聘、培训、薪酬设计等人力资源全流程服务，为创业企业解决人才难题。',
      contactInfo: ['电话：0371-3333333', '地址：示范区创新大厦5层'],
    ),
  ];

  // 特色资源数据
  final List<FeatureItemData> _featureItems = [
    FeatureItemData(
      icon: '📚',
      title: '创业知识库',
      description: '汇集创业指南、行业报告、成功案例等丰富的创业知识资源，为创业者提供学习和参考。',
    ),
    FeatureItemData(
      icon: '🔄',
      title: '资源对接平台',
      description: '线上线下相结合的资源对接平台，帮助创业者快速找到所需的技术、资金、人才等资源。',
    ),
    FeatureItemData(
      icon: '📅',
      title: '创业活动日历',
      description: '整合各类创业培训、路演、论坛等活动信息，方便创业者及时了解和参与相关活动。',
    ),
    FeatureItemData(
      icon: '📱',
      title: '移动服务平台',
      description: '提供手机端服务入口，让创业者随时随地获取所需资源和服务，提高创业效率。',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _opacityAnimation,
      builder: (context, child) {
        return Opacity(
          opacity: _opacityAnimation.value,
          child: child,
        );
      },
      child: Expanded(
        child: Container(
          // padding: EdgeInsets.all(20),
          constraints: BoxConstraints(maxWidth: 1200),
          // margin: EdgeInsets.symmetric(horizontal: 10),
          child: Column(
            children: [
              // 页面标题区域
              Container(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Colors.white, Color(0xFFf0f8ff)],
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                  ),
                  borderRadius: BorderRadius.circular(15),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black12,
                      blurRadius: 20,
                      offset: Offset(0, 5),
                    ),
                  ],
                ),
                padding: EdgeInsets.symmetric(vertical: 40),
                margin: EdgeInsets.only(bottom: 60),
                width: double.infinity,
                child: Column(
                  children: [
                    Text(
                      '双创资源',
                      style: TextStyle(
                        color: Color(0xFF1e3c72),
                        fontSize: 36,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(height: 15),
                    Text(
                      'Innovation and Entrepreneurship Resources',
                      style: TextStyle(
                        color: Color(0xFF666666),
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(height: 20),
                    Container(
                      constraints: BoxConstraints(maxWidth: 800),
                      padding: EdgeInsets.symmetric(horizontal: 20),
                      child: Text(
                        '整合各类创业创新资源，为创业者提供全方位的支持，包括成功案例参考、第三方服务机构对接等，助力创业项目快速成长。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                        textAlign: TextAlign.center,
                      ),
                    ),
                  ],
                ),
              ),

              // 成功案例部分
              ContentDoubleSection(
                title: '🏆 成功案例',
                subtitle: 'Success Cases',
                content: Column(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(bottom: 20),
                      child: Text(
                        '精选各类创业创新成功案例，分享创业经验和创新模式，为创业者提供借鉴和启发，少走弯路。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                    ),
                    ResourceGrid(cards: _successCaseCards),
                  ],
                ),
              ),

              // 第三方服务机构部分
              ContentDoubleSection(
                title: '🤝 第三方服务机构',
                subtitle: 'Third-party Service Organizations',
                content: Column(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(bottom: 20),
                      child: Text(
                        '第三方服务机构从咨询、金融、人力等方面帮助创业创新者分析，使其获取到最新的创业创新动态及自身的发展方向，掌握大量的经验，避免弯路和经济损失。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                    ),
                    ResourceGrid(cards: _thirdPartyServiceCards),
                  ],
                ),
              ),

              // 特色资源部分
              ContentDoubleSection(
                title: '🌟 特色资源',
                subtitle: 'Featured Resources',
                content: Column(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(bottom: 20),
                      child: Text(
                        '整合各类特色资源，为创业创新者提供多元化的支持，满足不同阶段、不同类型创业项目的需求。',
                        style: TextStyle(
                          color: Color(0xFF555555),
                          fontSize: 16,
                          height: 1.8,
                        ),
                      ),
                    ),
                    FeatureGrid(items: _featureItems),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// 资源卡片数据模型
class ResourceCardData {
  final String icon;
  final String name;
  final String type;
  final String description;
  final List<String> contactInfo;

  ResourceCardData({
    required this.icon,
    required this.name,
    required this.type,
    required this.description,
    required this.contactInfo,
  });
}

// 资源网格组件
class ResourceGrid extends StatelessWidget {
  final List<ResourceCardData> cards;

  ResourceGrid({required this.cards});

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      crossAxisCount: MediaQuery.of(context).size.width < 768 ? 1 : 3,
      crossAxisSpacing: 30,
      mainAxisSpacing: 30,
      childAspectRatio: 350 / 400,
      children: cards.map((card) => ResourceCard(data: card)).toList(),
    );
  }
}

// 资源卡片组件
class ResourceCard extends StatelessWidget {
  final ResourceCardData data;

  ResourceCard({required this.data});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(color: Color(0xFFe1e8ed)),
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black54,
            blurRadius: 15,
            offset: Offset(0, 3),
          ),
        ],
      ),
      child: Column(
        children: [
          // 卡片图标区域
          Container(
            height: 200,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFF4facfe), Color(0xFF00f2fe)],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              ),
            ),
            child: Center(
              child: Text(
                data.icon,
                style: TextStyle(
                  fontSize: 48,
                  color: Colors.white,
                ),
              ),
            ),
          ),
          // 卡片内容
          Padding(
            padding: EdgeInsets.all(25),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  data.name,
                  style: TextStyle(
                    color: Color(0xFF1e3c72),
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(
                  height: 12,
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: [Color(0xFF4facfe), Color(0xFF00f2fe)],
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                    ),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Text(
                    data.type,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 12,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  margin: EdgeInsets.only(bottom: 15),
                ),
                Text(
                  data.description,
                  style: TextStyle(
                    color: Color(0xFF666666),
                    height: 1.7,
                  ),
                ),
                SizedBox(
                  height: 15,
                ),
                if (data.contactInfo.isNotEmpty)
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: data.contactInfo.map((info) {
                      return Text(
                        info,
                        style: TextStyle(
                          color: Color(0xFF888888),
                          fontSize: 13,
                        ),
                      );
                    }).toList(),
                  ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 特色功能数据模型
class FeatureItemData {
  final String icon;
  final String title;
  final String description;

  FeatureItemData({
    required this.icon,
    required this.title,
    required this.description,
  });
}

// 特色功能网格组件
class FeatureGrid extends StatelessWidget {
  final List<FeatureItemData> items;

  FeatureGrid({required this.items});

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      crossAxisCount: MediaQuery.of(context).size.width < 768 ? 1 : 2,
      crossAxisSpacing: 25,
      mainAxisSpacing: 25,
      childAspectRatio: 280 / 200,
      children: items.map((item) => FeatureItem(data: item)).toList(),
    );
  }
}

// 特色功能项组件
class FeatureItem extends StatelessWidget {
  final FeatureItemData data;

  FeatureItem({required this.data});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFFf8fbff), Color(0xFFf0f8ff)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        border: Border.all(color: Color(0xFFe1e8ed)),
        borderRadius: BorderRadius.circular(12),
      ),
      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 30),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            data.icon,
            style: TextStyle(
              fontSize: 40,
              color: Color(0xFF1e3c72),
            ),
          ),
          SizedBox(
            height: 15,
          ),
          Text(
            data.title,
            style: TextStyle(
              color: Color(0xFF1e3c72),
              fontSize: 18,
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            data.description,
            style: TextStyle(
              color: Color(0xFF666666),
              fontSize: 14,
              height: 1.6,
            ),
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}
